/**
 * @Project Name:hoofungson-elk-log
 * @Package Name:cn.hoofungson.framework.elk.log.util
 * @Since JDK 1.8
 */

package cn.hoofungson.framework.elk.log.util;

import org.apache.commons.lang3.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description: JSON工具
 * @Author 胡松 hoofungson@163.com
 * @Date 2019-09-10 20:30
 * @Version V1.0
 */
public class JSONUtils {

    /**
     * 字符串处理特殊字符
     *
     * @param content
     * @return
     **/
    public static String filter(String content) {
        if (StringUtils.isEmpty(content)) {
            return StringUtils.EMPTY;
        }
        Map<String, String> words = new LinkedHashMap<>();
        words.put("\\", "\\\\");
        words.put("\n", "\\\\n");
        words.put(":", "\\\\:");
        words.put("\f", "\\\\f");
        words.put("\b", "\\\\b");
        words.put("\r", "\\\\r");
        words.put("\t", "\\\\t");

        for (String key : words.keySet()) {
            content = StringUtils.replace(content, key, words.get(key));
        }
        return content;
    }
}